package com.example.AliSDK;

import android.app.Activity;
import android.util.Log;
import android.widget.Toast;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.sdk.android.AlibabaSDK;
import com.alibaba.sdk.android.openaccount.callback.LoginCallback;
import com.alibaba.sdk.android.openaccount.model.OpenAccountSession;
import com.alibaba.sdk.android.openaccount.ui.OpenAccountUIService;
import com.aliyun.alink.business.alink.ALinkResponse;
import com.aliyun.alink.business.login.IOpenLoginAdaptor;
import com.aliyun.alink.utils.ALog;
import com.aliyun.alink.business.login.OpenLoginBusiness;
import com.taobao.weex.bridge.JSCallback;
import com.taobao.weex.common.WXModule;
import com.taobao.weex.common.WXModuleAnno;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016-7-28.
 */
public class WeexLogin extends WXModule{



    @WXModuleAnno
    public void clickLogin(final JSCallback callback){

        //Toast.makeText(mWXSDKInstance.getContext(), "这是封装的Module", Toast.LENGTH_SHORT).show();
        OpenAccountUIService openAccountUIService = AlibabaSDK.getService(OpenAccountUIService.class);
        openAccountUIService.showLogin((Activity) mWXSDKInstance.getContext(), new LoginCallback() {
            @Override
            public void onSuccess(OpenAccountSession openAccountSession) {
                //Toast.makeText(mWXSDKInstance.getContext(), "1", Toast.LENGTH_SHORT).show();

                Map<String,Object> resp = new HashMap();
                resp.put("UserID",openAccountSession.getUserId());
                resp.put("AuthorizationCode",openAccountSession.getAuthorizationCode());
                Log.d("data", String.valueOf(resp));
                callback.invoke(resp);
                OpenLoginBusiness.loginAlink();
            }
            @Override
            public void onFailure(int i, String s) {
                Toast.makeText(mWXSDKInstance.getContext(), "用户退出了", Toast.LENGTH_SHORT).show();
            }
        });

    }
    @WXModuleAnno
    public  void toast(String msg){
        Toast.makeText(mWXSDKInstance.getContext(), msg , Toast.LENGTH_SHORT).show();
    }
}
